package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.converter.UserConverter;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.app.*;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.UserRemindCommand;
import com.cskaoyan.wordmemorize.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "移动端-用户(我的)模块")
@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    UserService userService;
    @Autowired
    UserConverter userConverter;

    @Operation(summary = "***获取用户信息",
            description = "在用户打开APP或者其他路由跳转的时候，通过token获取用户信息",
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "成功. 返回登录成功的用户信息，以及当前等级权限码集合"
                    ),
                    @ApiResponse(responseCode = "500",
                            description = "请求失败"
                    )
            }
    )
    @GetMapping("info")
    public Result<UserDTO> getUserInfo() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        UserDTO userInfo = userService.getUserInfo(userId);
        return Result.ok(userInfo);
    }
    @PutMapping("remind")
    public Result<UserDTO> updateUserRemind(@RequestBody UserRemindCommand command) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userService.updateUserRemind(command,userId);
        return Result.ok();
    }
    @PutMapping ("day/voc")
    public Result<UserDTO> updateVocCountOfDay(@RequestParam("count") Integer count) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        userService.updateVocCountOfDay(userId,count);
        return Result.ok();
    }
    @GetMapping("/voc/my/page")
    public Result<UserPageDTO> getUserPage() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        UserPageDTO userPageDTO=userService.getUserPage(userId);
        return Result.ok(userPageDTO);
    }
    @GetMapping("/voc/bound/statistics")
    public Result<UserVocBoundStatisticsDTO> getUserVocBoundStatistics() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        UserVocBoundStatisticsDTO userVocBoundStatisticsDTO=userService.getUserVocBoundStatistics(userId);
        return Result.ok(userVocBoundStatisticsDTO);
    }
    //public PageDTO<DisplayUserVocBoundLogDTO> getUserVocBoundLog(PageRequest pageRequest, Long userId)
    @GetMapping("voc/bound/detail")
    public Result<PageDTO<DisplayUserVocBoundLogDTO>> getUserVocBoundLog(@RequestBody PageRequest pageRequest) {
        Long userId = StpKit.USER.getLoginIdAsLong();
        PageDTO<DisplayUserVocBoundLogDTO> pageDTO=userService.getUserVocBoundLog(pageRequest,userId);
        return Result.ok(pageDTO);
    }
    @GetMapping("upgrade/info")
    public Result<NextLevelDTO> getUserNextDTO() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        NextLevelDTO nextLevelDTO=userService.getUserNextDTO(userId);
        return Result.ok(nextLevelDTO);
    }
    @GetMapping("level/info")
    public Result<DisplayUserLevelDTO> getUserLevelInfo() {
        Long userId = StpKit.USER.getLoginIdAsLong();
        DisplayUserLevelDTO displayUserLevelDTO=userService.getUserLevelInfo(userId);
        return Result.ok(displayUserLevelDTO);
    }
}
